<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    let arr = [1, 3, 5, 7, 9, 2, 4, 6, 8, 10]
    function fn(arr) {
      let temp
      // -1是因为最后一个数一定时最大的,不需要遍历
      for (let i = 0; i < arr.length - 1; i++) {
        // 不用遍历最后一位
        for (let j = 0; j < arr.length - 1 - i; j++) {
          if (arr[j] > arr[j + 1]) {
            temp = arr[j]
            arr[j] = arr[j + 1]
            arr[j + 1] = temp
          }
        }
      }
      return arr
    }
    console.log(fn(arr));
  </script>
</body>

</html>